﻿using System;
using System.Linq.Expressions;
using _5E.Infrastructure.Expression;

namespace _5E.Infrastructure.Querying
{
    public class Criterion
    {
        private string m_PropertyName = null;
        public string PropertyName
        {
            get { return m_PropertyName; }
            set { m_PropertyName = value; }
        }

        private object m_Value = null;
        public object Value
        {
            get { return m_Value; }
            set { m_Value = value; }
        }

        private CriteriaOperator m_CriteriaOperator;
        public CriteriaOperator CriteriaOperator
        {
            get { return m_CriteriaOperator; }
            set { m_CriteriaOperator = value; }
        }

        public Criterion(string propertyName, object value, CriteriaOperator criteriaOperator)
        {
            m_PropertyName = propertyName;
            m_Value = value;
            m_CriteriaOperator = criteriaOperator;
        }

        public static Criterion Create<T>(Expression<Func<T, object>> expression, CriteriaOperator criteriaOperator, object value = null)
        {
            string propertyName = PropertyNameHelper.ResolvePropertyName<T>(expression);
            return new Criterion(propertyName, value, criteriaOperator);
        }
    }
}
